package com.spvs.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spvs.common.log.annotation.Log;
import com.spvs.common.log.enums.BusinessType;
import com.spvs.common.security.annotation.RequiresPermissions;
import com.spvs.system.domain.FileRecycleBin;
import com.spvs.system.service.IFileRecycleBinService;
import com.spvs.common.core.web.controller.BaseController;
import com.spvs.common.core.web.domain.AjaxResult;
import com.spvs.common.core.utils.poi.ExcelUtil;
import com.spvs.common.core.web.page.TableDataInfo;

/**
 * 文件回收站Controller
 *
 * @author supervision
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/bin")
public class FileRecycleBinController extends BaseController
{
    @Autowired
    private IFileRecycleBinService fileRecycleBinService;

    /**
     * 查询文件回收站列表
     */
    @RequiresPermissions("system:bin:list")
    @GetMapping("/list")
    public TableDataInfo list(FileRecycleBin fileRecycleBin)
    {
        startPage();
        List<FileRecycleBin> list = fileRecycleBinService.selectFileRecycleBinList(fileRecycleBin);
        return getDataTable(list);
    }

    /**
     * 导出文件回收站列表
     */
    @RequiresPermissions("system:bin:export")
    @Log(title = "文件回收站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileRecycleBin fileRecycleBin)
    {
        List<FileRecycleBin> list = fileRecycleBinService.selectFileRecycleBinList(fileRecycleBin);
        ExcelUtil<FileRecycleBin> util = new ExcelUtil<FileRecycleBin>(FileRecycleBin.class);
        util.exportExcel(response, list, "文件回收站数据");
    }

    /**
     * 获取文件回收站详细信息
     */
    @RequiresPermissions("system:bin:query")
    @GetMapping(value = "/{recycleBinId}")
    public AjaxResult getInfo(@PathVariable("recycleBinId") Long recycleBinId)
    {
        return success(fileRecycleBinService.selectFileRecycleBinByRecycleBinId(recycleBinId));
    }

    /**
     * 新增文件回收站
     */
    @RequiresPermissions("system:bin:add")
    @Log(title = "文件回收站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FileRecycleBin fileRecycleBin)
    {
        return toAjax(fileRecycleBinService.insertFileRecycleBin(fileRecycleBin));
    }

    /**
     * 修改文件回收站
     */
    @RequiresPermissions("system:bin:edit")
    @Log(title = "文件回收站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FileRecycleBin fileRecycleBin)
    {
        return toAjax(fileRecycleBinService.updateFileRecycleBin(fileRecycleBin));
    }

    /**
     * 删除文件回收站
     */
    @RequiresPermissions("system:bin:remove")
    @Log(title = "文件回收站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recycleBinIds}")
    public AjaxResult remove(@PathVariable Long[] recycleBinIds)
    {
        return toAjax(fileRecycleBinService.deleteFileRecycleBinByRecycleBinIds(recycleBinIds));
    }
}
